﻿namespace ScrumLite.Services.Contracts
{
    using System;
    using System.Runtime.Serialization;

    [DataContract()]
    public class Measure
    {
        [DataMember]
        public string Name { get; set; }
        
        [DataMember]
        public int Value { get; set; }
        
        [DataMember]        
        public string Unit { get; set; }
        
        [DataMember]        
        public DateTime LastMeasure { get; set; }

        [DataMember]
        public MeasureStatus Status
        { 
            get
            {
                if (AscendantMeasure)
                { 
                    if (Value < LowThresholdValue )
                        return MeasureStatus.Bad;
                    else if (Value >= LowThresholdValue &&  Value <= HighThresholdValue)
                        return MeasureStatus.Regular;
                    else
                        return MeasureStatus.Good;
                }
                else
                {
                    if (Value < LowThresholdValue)
                        return MeasureStatus.Good;
                    else if (Value >= LowThresholdValue && Value <= HighThresholdValue)
                        return MeasureStatus.Regular;
                    else
                        return MeasureStatus.Bad;
                }
            }
            //Set Method must exist (serialization requires)
            private set { }
        }

        [DataMember]
        public int LowThresholdValue { get; set; }

        [DataMember]
        public int HighThresholdValue { get; set; }

        [DataMember]
        public bool AscendantMeasure { get; set; }
    }

    public enum MeasureStatus : int
    {
        Bad = 1,
        Regular = 2,
        Good = 3
    }        
}
